﻿<%@LANGUAGE="VBSCRIPT" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contractor Instructions</title>
<%
contractor=request.QueryString("contractor")
emergency=request.QueryString("emergency")
during=request.QueryString("during")
theday=request.QueryString("theday")
if (contractor<>"") and (emergency<>"") and (during <>"") and (theday<>"") then
	dim db,rs
	set db=server.CreateObject("adodb.connection")
	set rs=server.CreateObject("adodb.recordset")
	filepath=server.MapPath("access/backend/DBHub.mdb")
	contractor=replace(contractor,"_"," ")
	db.open ("provider=microsoft.jet.oledb.4.0;data source=" & filepath)
	sql="select [" & theday & " " & emergency & " " & during & "], name from AfterHours_contractors where [code]='" & contractor & "'"
	rs.open sql,db,1,2
	header="Instructions for '" & rs("name") & "' " & emergency & " " & during & " available time." 
	if rs.eof then
		instructions="(error retrieving instruction)"
	else
		ra=rs.getrows()
		instructions=ra(0,0)
		
		if not isnull(instructions) then
			instructions=replace(instructions,chr(13),"<br/>")
				
			rasegs=split(instructions,"<br/>")
			seglen=45
			for z=0 to ubound(rasegs)
				if len(rasegs(z))>seglen then
					temp=""
					laststop=1
					segcounter=0
					curpos=0
					curpos=0
					do until curpos>len(rasegs(z))
						curpos=curpos+1
						segcounter=segcounter+1
						if curpos=len(rasegs(z)) then
							thisseg=mid(rasegs(z),laststop+1,curpos-laststop) & "<br/>"
							temp=temp & thisseg
							exit do
						end if
					
						if segcounter=seglen then
							segcounter=0
							if mid(rasegs(z),curpos,1)<>" " then
								revert=curpos
								do until mid(rasegs(z),curpos,1)=" "
									curpos=curpos-1
									if curpos=0 then
										curpos=revert
										exit do
									end if
								loop
							end if
							thisseg=mid(rasegs(z),laststop,curpos-laststop) & "<br/>"
							temp=temp & thisseg
							laststop=curpos
						end if	
					loop 
				
					temp=left(temp,len(temp)-5)
					rasegs(z)=temp
				end if
			next
			'if ra(1,x)="ars" then response.End()
			instructions=join(rasegs,"<br/>")
			instructions=replace(instructions," ","&nbsp;") 
		else
			instructions="(no instructions set for given criteria)"
		end if
	end if
	rs.close
	db.close
	set rs=nothing
	set db=nothing
else
	instructions=""
	header=""
end if
%>
<link href="UniversalStyleSheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="280" cellspacing="1" bgcolor="#009900">
<tr>
  <td class="TableTitles" bgcolor="#FFFFFF"><p><%= instructions %></p></td>
</tr>
</table>

</body>
</html>
